<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Services\GoodService;
use Encore\Admin\Layout\Content;
use Encore\Admin\Widgets\Box;

class GoodChartController extends Controller {

	/**
	 * Index interface.
	 *
	 * @param Content $content
	 * @return Content
	 */
	public function index(Content $content) {
		$data = $this->chartData();

		return $content
			->header('数据统计')
			->description('商品数据图表分析')
			->body(new Box('图表展示', view('admin.chart.goodPinxiang',
				['data' => $data])));
	}

	/**
	 * 图表数据
	 * @Author   wangwenfan
	 * @DateTime 2019-11-06
	 * @return   array
	 */
	private function chartData() {
		$groupData = GoodService::appearance();
		$pinxiang = array_column($groupData, 'pinxiang');
		$number = array_column($groupData, 'num');
		$data = [
			'pinxiang' => $pinxiang,
			'number' => $number,
		];
		return $data;
	}

}
